import sys
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel
from PyQt5.QtCore import Qt
from config import button_config,Text_config
from login import Login
from register import Register
from client.client_socket import UserClient


class Origin(QWidget):
    def __init__(self,client):
        super().__init__()
        self.client=client
        self.resize(400, 600)
        self.setWindowTitle("购物商场")
        icon = QIcon('../static/img/商城图标.png')
        self.setWindowIcon(icon)
        mainLayout = QVBoxLayout(self)
        self.initUI(mainLayout)
    def initUI(self,layout):
        logo=QLabel(self)
        img=QPixmap('../static/img/商城图标.png')
        img=img.scaled(200, 200, Qt.KeepAspectRatio)
        logo.setPixmap(img)
        logo.setAlignment(Qt.AlignCenter)
        layout.addWidget(logo)

        text=QLabel('请选择你的操作')
        text.setStyleSheet(Text_config.text_style1)
        text.setAlignment(Qt.AlignCenter)
        layout.addWidget(text)

        register_button=QPushButton('注册')
        login_button=QPushButton('登录')
        exit_button=QPushButton('退出')
        for i in (register_button,login_button,exit_button):
            i.setMinimumHeight(100)
        register_button.setStyleSheet(button_config.button_style1)
        login_button.setStyleSheet(button_config.button_style2)
        exit_button.setStyleSheet(button_config.button_style3)
        layout.addWidget(register_button)
        layout.addWidget(login_button)
        layout.addWidget(exit_button)
        register_button.clicked.connect(self.register)
        login_button.clicked.connect(self.login)
        exit_button.clicked.connect(self.exit)



    def login(self):
        self.window=Login(self)
        self.window.show()
        self.close()
    def register(self):
        self.window=Register(self)
        self.window.show()
        self.close()
    def exit(self):
        self.close()



if __name__ == '__main__':
    user_client=UserClient()
    app = QApplication(sys.argv)
    window = Origin(user_client)
    window.show()
    sys.exit(app.exec_())